package com.afinal.intelligencetrash.Model.interfaces;

import com.afinal.intelligencetrash.Model.bean.User;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * Created by cyy on 17-10-8.
 */

public abstract class RequestHolder<T> implements RequestCallBack{
    @Override
    public void onRequestSuccess(String result) {
        Gson gson = new Gson();
        User r = gson.fromJson(result, new TypeToken<User>(){}.getType());
        OnSuccess(r);
        OnFinal(true);
    }

    @Override
    public void onRequestFailure(int statusCode, String error) {
        OnFailure(statusCode, error);
        OnFinal(false);
    }


    protected abstract void OnSuccess(User result);
    protected abstract void OnFailure(int statusCode, String error);
    protected abstract void OnFinal(boolean isSuccess);
}
